cmake_minimum_required(VERSION 3.10)  

get_filename_component(CURRENT_DIR_PATH "${CMAKE_CURRENT_LIST_DIR}" ABSOLUTE) 
get_filename_component(CURRENT_DIR_NAME "${CURRENT_DIR_PATH}" NAME) 
project(${CURRENT_DIR_NAME})

set(CMAKE_CXX_STANDARD 11) 

if(MSVC)
	add_compile_options(/Zc:__cplusplus)
endif()

SET(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON)

SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_AUTOUIC ON)

find_package(Qt5 COMPONENTS Core Widgets Gui REQUIRED PrintSupport LinguistTools)

set(UI_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.ui
)

set(RCC_FILES
	${CMAKE_CURRENT_SOURCE_DIR}/image.qrc
)

set(HEADER_FILES
	${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.h
	${CMAKE_CURRENT_SOURCE_DIR}/formatcontroller.h
	${CMAKE_CURRENT_SOURCE_DIR}/menubar.h
	${CMAKE_CURRENT_SOURCE_DIR}/documenttabwidget.h
)
set(CPP_FILES
	${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
	${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.cpp
	${CMAKE_CURRENT_SOURCE_DIR}/formatcontroller.cpp
	${CMAKE_CURRENT_SOURCE_DIR}/menubar.cpp
)

qt5_wrap_ui(UI_HEADERS ${UI_FILES})
set(TS_FILES ${CMAKE_SOURCE_DIR}/mui/zh_CN/translate_zh.ts)
set(QM_OUTPUT_DIR ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/mui/zh_CN/)

qt5_create_translation(QM_FILES ${HEADER_FILES} ${CPP_FILES} ${UI_FILES} ${TS_FILES})
add_executable(${PROJECT_NAME} WIN32 ${HEADER_FILES} ${CPP_FILES} ${UI_FILES} ${RCC_FILES})



target_include_directories(${PROJECT_NAME} PRIVATE
     ${CMAKE_CURRENT_SOURCE_DIR}/../ribbontoolbar
	 ${CMAKE_CURRENT_SOURCE_DIR}/../formatpanel
	 ${CMAKE_CURRENT_SOURCE_DIR}/../editorwidget
)

target_link_directories(${PROJECT_NAME} PRIVATE
    ${CMAKE_BINARY_DIR}/bin
)
target_link_libraries(${PROJECT_NAME} 
	Qt5::Widgets
	Qt5::Core
	Qt5::Gui
	Qt5::PrintSupport  # 必须添加此行，主程序直接依赖
	ribbontoolbar
	formatpanel
	editorwidget

)
add_custom_target(translations_${PROJECT_NAME} DEPENDS ${QM_FILES})
add_dependencies(${PROJECT_NAME} translations_${PROJECT_NAME})

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory ${QM_OUTPUT_DIR}
    COMMAND ${CMAKE_COMMAND} -E copy ${QM_FILES} ${QM_OUTPUT_DIR}
    COMMENT "Copying .qm files to ${QM_OUTPUT_DIR}"
)
